package com.xiaolin.mybatis.service;

import com.xiaolin.mybatis.mapper.UserMapper;
import com.xiaolin.mybatis.model.User;
import com.xiaolin.mybatis.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @ClassName UserService
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/7
 * @Version 1.0
 */
public class UserService {
    public static void main(String[] args) {
        String resource="mybatis-config.xml";
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.sqlSessionFactory(resource);
        // 使用try-with-resource进行SqlSession的关闭
        try(SqlSession session = sqlSessionFactory.openSession()) {
            UserMapper mapper = session.getMapper(UserMapper.class);
//            User user = mapper.getById(41);
//            System.out.println(user);
            List<User> list = mapper.getList();
            System.out.println(list);
        }
    }
}
